<template>
	<view class="product-list">
		<!--分类栏目-->
		<!--商品列表-->
		<view class="rf-product-list" :style="{marginTop: contentTop}" v-if="goodsList.length > 0">
			<view v-for="(item, index) in goodsList" :key="index" class="product-item" @tap="navTo(item)">
				<view class="image-wrapper">
					<image :src="item.picture" mode="aspectFill"></image>
				</view>
				<text class="title clamp in2line" v-if="item.name">{{item.name}}</text>
				<view class="last-line" v-if="item.name">
					<text class="price in1line" v-if="vip==1">{{item.product_mdl}}</text>
					<text class="price1 in1line" v-if="vip==2">{{item.price}}
						<text class="m-price">赠送:</text>
					</text>
					<text class="sales in1line" v-if="vip==2">
						<text>{{ item.give_mdl }}贡献值</text>
					</text>
				</view>
			</view>
		</view>
		<rf-load-more :status="loadingType" v-if="goodsList.length > 0"></rf-load-more>
		<rf-empty :info="errorInfo || '该分类暂无商品'" v-if="goodsList.length === 0 && !loading" style="margin-top: 50px"></rf-empty>
		<!--页面加载动画-->
		<rf-loading v-if="loading"></rf-loading>
	</view>
</template>

<script>
	import {
		guessYouLikeList,
		productCate,
		productList
	} from "@/api/product";
	import {vipProduct} from "@/api/product";
	import {vipgoods} from"@/api/userInfo.js"
	import rfLoadMore from '@/components/rf-load-more/rf-load-more';
	import rfRecommend from '@/components/rf-recommend/rf-recommend';
	import rfSearchBar from '@/components/rf-search-bar/rf-search-bar';

	export default {
		components: {
			rfLoadMore,
			rfSearchBar,
			rfRecommend,
		},
		data() {
			return {
				loading: true, // 加载动画
				headerShow: true,
				navBarTop: "100upx",
				cateMaskState: 0, //分类面板展开状态
				headerPosition: "fixed",
				headerTop: "0px",
				loadingType: 'more', //加载更多状态
				filterIndex: 0,
				cateId: 0, //已选三级分类id
				priceOrder: 0, //1 价格从低到高 2价格从高到低
				salesOrder: 0, //1 价格从低到高 2价格从高到低
				cateList: [],
				goodsList: [], // 商品列表
				keyword: null, // 搜索关键字
				cateParams: null,
				page: 1,
				filterParams: {},
				isShowNavBar: true,
				hotSearchDefault: '请输入关键字',
				contentTop: '30upx',
				errorInfo: undefined, // 接口请求出错信息
				vip:""
				
			};
		},
		onLoad(options) {
			if(options.dvip==1){
				this.isShowNavBar=false
				this.getvipgds()
				this.vip=1
			}
			if(options.dvip==2){
				uni.setNavigationBarTitle({
				    title: '会员专区'
				});
				this.vip=2
				this.isShowNavBar=false
				this.getInfo()
			}
		},
		onShow() {
			if (navigator) {
				// this.headerTop = document.getElementsByTagName('uni-page-head')[0] && document.getElementsByTagName('uni-page-head')[
				// 	0].offsetHeight + 'px';
			}
		},
		onPageScroll(e) {
			//兼容iOS端下拉时顶部漂移
			if (e.scrollTop >= 0) {
				this.headerPosition = "fixed";
			} else {
				this.headerPosition = "absolute";
			}
		},
		//下拉刷新
		onPullDownRefresh() {
			// this.filterParams = {};
			// this.page = 1;
			// this.goodsList = [];
		},
		//加载更多
		onReachBottom() {
			this.page++;
			if(this.vip==1){
				this.getvipgds()
			}
			if(this.vip==2){
				this.getInfo()
			}
		},
		methods: {
			// 会员专区
			getInfo(){
				this.$get(vipProduct,{page:this.page}).then(r=>{
					this.loading=false
					console.log(r);
					r.data.forEach(item=>{
						this.goodsList.push(item);
					})
				})
			},
			
			// 获取积分兑换的商品
			getvipgds(){
				this.$get(vipgoods,{page:this.page}).then(res=>{
					this.loading=false
					console.log(res)
					res.data.forEach(item=>{
						this.goodsList.push(item)
					})
				})
			},
			// 跳转至主页
			navToIndex() {
				uni.switchTab({
					url: `/pages/index/index`
				})
			},
			navTo(item){
				if(this.vip==1){
					uni.navigateTo({
						url:`/pages/product/product?id=${item.id}&vipgd=1`
					})
				}
				if(this.vip==2){
					uni.navigateTo({
						url:`/pages/product/product?id=${item.id}`
					})
				}
			}
		},
	}
</script>

<style lang="scss">
	page {
		background: $page-color-white;
	}

	.product-list {
		.navbar {
			position: fixed;
			left: 0;
			/*top: var(--window-top);*/
			display: flex;
			width: 100%;
			height: 80upx;
			background: #fff;
			box-shadow: 0 2upx 10upx rgba(0, 0, 0, .06);
			z-index: 10;

			.nav-item {
				flex: 1;
				display: flex;
				justify-content: center;
				align-items: center;
				height: 100%;
				font-size: 30upx;
				color: $font-color-dark;
				position: relative;

				&.current {
					color: $base-color;

					&:after {
						content: '';
						position: absolute;
						left: 50%;
						bottom: 0;
						transform: translateX(-50%);
						width: 120upx;
						height: 0;
						border-bottom: 4upx solid $base-color;
					}
				}
			}

			.p-box {
				display: flex;
				flex-direction: column;

				.iconfont {
					display: flex;
					align-items: center;
					justify-content: center;
					width: 30upx;
					height: 14upx;
					line-height: 1;
					margin-left: 4upx;
					font-size: 26upx;
					color: #888;

					&.active {
						color: $base-color;
					}
				}

				.xia {
					transform: scaleY(-1);
				}
			}

			.cate-item {
				display: flex;
				justify-content: center;
				align-items: center;
				height: 100%;
				width: 80upx;
				position: relative;
				font-size: 44upx;

				&:after {
					content: '';
					position: absolute;
					left: 0;
					top: 50%;
					transform: translateY(-50%);
					border-left: 1px solid #ddd;
					width: 0;
					height: 36upx;
				}
			}
		}

		/* 分类 */
		.cate-mask {
			position: fixed;
			left: 0;
			top: 40px;
			bottom: 0;
			width: 100%;
			background: rgba(0, 0, 0, 0);
			z-index: 95;
			transition: .3s;

			.cate-content {
				width: 630upx;
				height: 100%;
				background: #fff;
				float: right;
				transform: translateX(100%);
				transition: .3s;
			}

			&.none {
				display: none;
			}

			&.show {
				background: rgba(0, 0, 0, .4);

				.cate-content {
					transform: translateX(0);
				}
			}

			.cate-list {
				display: flex;
				flex-direction: column;
				height: 100%;

				.cate-item {
					display: flex;
					align-items: center;
					height: 70upx;
					padding-left: 30upx;
					font-size: 30upx;
					position: relative;
					color: $font-color-dark;
				}

				.one {
					background: #eee;
				}

				.two {
					background: #f8f8f8;
					color: $font-color-base;
					height: 60upx;
					font-size: 28upx;
					padding-left: 50upx;
				}

				.three {
					font-size: 26upx;
					color: $font-color-base;
					max-width: 108upx;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}

				.active {
					color: $base-color;
				}
			}
		}
	}
</style>

